package com.app.demo.activitys;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.app.demo.R;
import com.app.demo.beans.XjxxBean;

import com.app.shop.mylibrary.base.BaseActivity;
import com.app.shop.mylibrary.beans.EventMessage;
import com.app.shop.mylibrary.utils.UserManager;

import org.litepal.crud.DataSupport;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class XJXXActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_class)
    TextView tvClass;
    @BindView(R.id.tv_id)
    TextView tvId;

    XjxxBean bean = null;


    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xjxx);
        ButterKnife.bind(this);
        initData();
        setView();
    }

    private void setView() {

        List<XjxxBean> list = DataSupport.findAll(XjxxBean.class);
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getUser_id().equals(UserManager.getUserId(this))) {
                bean = list.get(i);
            }
        }
        if (bean != null) {
            tvName.setText("姓名：" + bean.getUser_name());
            tvClass.setText("班级：" + bean.getGrade());
            tvId.setText("学号：" + bean.getUser_id());
        }
    }

    private void initData() {
        tvTitle.setText("学籍信息");
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText("修改");
    }


    @Override
    public void onEvent(EventMessage msg) {
        super.onEvent(msg);
        if (msg.getMessageType() == EventMessage.Refresh) {
            setView();
        }
    }

    @OnClick({R.id.imgv_return, R.id.tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.imgv_return:
                onBackPressed();
                break;
            case R.id.tv_right:

                Bundle bundle = new Bundle();
                bundle.putSerializable("bean", bean);
                showActivity(this, ModifyXjxxActivity.class, bundle);
                break;

        }
    }



}
